package vn.student.Adapter;

import vn.student.database.SQLDataHelper;
import vn.student.mode.TitleProvider;
import vn.student.notificationforandroid.R;
import android.app.Activity;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ListView;

public class ViewPagerAdapter extends PagerAdapter implements TitleProvider {
    private static String[] titles;
    private final Activity context;
    LayoutInflater mLayoutInflater;
    public static String TAG = "View Page Adateper";
    SQLDataHelper mSqlHelper;

    public ViewPagerAdapter(Activity context, SQLDataHelper mSqlHelper) {
	this.context = context;
	ViewPagerAdapter.titles = context.getResources().getStringArray(
		R.array.title);
	mLayoutInflater = LayoutInflater.from(context);
	this.mSqlHelper = mSqlHelper;
    }

    public String getTitle(int position) {
	return titles[position];
    }

    @Override
    public int getCount() {
	return titles.length;
    }

    @Override
    public Object instantiateItem(View pager, int position) {

	View v = null;
	ManagePage PAGE = new ManagePage(context, mSqlHelper);
	switch (position) {

	case 0:

	    v = PAGE.getLayout(position);
	    break;
	case 1:
	    v = PAGE.getLayout(position);
	    break;
	case 2:

	    v = mLayoutInflater.inflate(R.layout.row_page_canhan, null);

	    break;
	default:
	    v = mLayoutInflater.inflate(R.layout.canhancreate_page, null);
	    break;
	}

	((ViewPager) pager).addView(v, 0);
	return v;
    }

    static class HorderPage {
	ListView list;
    }

    @Override
    public void destroyItem(View pager, int position, Object view) {
	((ViewPager) pager).removeView((View) view);
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
	return view.equals(object);
    }

    @Override
    public void finishUpdate(View view) {
    }

    @Override
    public void restoreState(Parcelable p, ClassLoader c) {
    }

    @Override
    public Parcelable saveState() {
	return null;
    }

    @Override
    public void startUpdate(View view) {
    }

}